/**
 * https://leetcode.cn/problems/n-ary-tree-level-order-traversal/submissions/585324443/
 * 429. N 叉树的层序遍历
 * medium 陈贝纯 2024.12.05
 * bfs
 */

/*
// Definition for a Node.
class Node {
public:
    int val;
    vector<Node*> children;

    Node() {}

    Node(int _val) {
        val = _val;
    }

    Node(int _val, vector<Node*> _children) {
        val = _val;
        children = _children;
    }
};
*/

class Solution {
public:
    vector<vector<int>> levelOrder(Node* root) {
        queue<Node*>  q;
        vector<vector<int>> ans;
        if(!root)
        return ans;
        q.push(root);
        while(!q.empty()){
            int k=q.size();
            vector<int> v;
            while(k--){
                Node* p=q.front();
                q.pop();
                v.push_back(p->val);
                for(auto &child:p->children)
                    q.push(child);
            }
            ans.push_back(v);
        }
        return ans;
    }
};